<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="" prop="internalOrderNumber">
        <el-input
          v-model="queryParams.internalOrderNumber"
          placeholder="请输入内部订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="payDay">
        <el-date-picker
          clearable
          v-model="queryParams.payDay"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择支付日期-天"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="支付日期" prop="dataDate">
        <!-- <el-date-picker
          clearable
          v-model="queryParams.dataDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="支付日期"
        >
        </el-date-picker> -->
        <el-date-picker
          v-model="value2"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
          @change="changeTime"
          size="mini"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="" prop="origOnlineOrderNumber">
        <el-input
          v-model="queryParams.origOnlineOrderNumber"
          placeholder="请输入原始线上订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="onlineColorSpecification">
        <el-input
          v-model="queryParams.onlineColorSpecification"
          placeholder="线上颜色规格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
          size="mini"
          @click="shouqi"
          >展开/收起</el-button
        >
      </el-form-item>
      <div v-if="isOpen">
        <el-form-item label="" prop="orderProperties">
          <el-input
            v-model="queryParams.orderProperties"
            placeholder="请输入订单属性"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="shopName">
          <el-input
            v-model="queryParams.shopName"
            placeholder="请输入店铺"
            clearable
            @keyup.enter.native="handleQuery"
          />
          <!-- <el-select v-model="queryParams.shopName" placeholder="店铺名称" clearable @change="getList">
          <el-option v-for="dict in dict.type.sys_product_live" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select> -->
        </el-form-item>
        <el-form-item label="" prop="multiLabel">
          <el-input
            v-model="queryParams.multiLabel"
            placeholder="请输入标记多标签"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="buyerId">
          <el-input
            v-model="queryParams.buyerId"
            placeholder="请输入"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="buyerMark">
          <el-input
            v-model="queryParams.buyerMark"
            placeholder="请输入卖家备注"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="payDate">
          <el-date-picker
            clearable
            v-model="queryParams.payDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择支付日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="province">
          <el-input
            v-model="queryParams.province"
            placeholder="请输入省"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="city">
          <el-input
            v-model="queryParams.city"
            placeholder="请输入市"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="afterSalesClassification">
          <el-input
            v-model="queryParams.afterSalesClassification"
            placeholder="请输入售后分类"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="productCode">
          <el-input
            v-model="queryParams.productCode"
            placeholder="请输入商品编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="productNo">
          <el-input
            v-model="queryParams.productNo"
            placeholder="请输入款式编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item label="" prop="onlineOrderNumber">
          <el-input
            v-model="queryParams.onlineOrderNumber"
            placeholder="请输入原始线上订单号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
        <el-form-item label="" prop="brand">
          <el-input
            v-model="queryParams.brand"
            placeholder="请输入品牌"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="basicSellingPrice">
          <el-input
            v-model="queryParams.basicSellingPrice"
            placeholder="请输入基本售价"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="costPrice">
          <el-input
            v-model="queryParams.costPrice"
            placeholder="请输入成本价"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="salesNum">
          <el-input
            v-model="queryParams.salesNum"
            placeholder="请输入销售数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="salesAmount">
          <el-input
            v-model="queryParams.salesAmount"
            placeholder="请输入销售金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="salesCost">
          <el-input
            v-model="queryParams.salesCost"
            placeholder="请输入销售成本"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="salesGrossProfit">
          <el-input
            v-model="queryParams.salesGrossProfit"
            placeholder="请输入销售毛利"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="returnNum">
          <el-input
            v-model="queryParams.returnNum"
            placeholder="请输入退货数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="actualReturnNum">
          <el-input
            v-model="queryParams.actualReturnNum"
            placeholder="请输入实退数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="returnAmount">
          <el-input
            v-model="queryParams.returnAmount"
            placeholder="请输入退货金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="actualReturnAmount">
          <el-input
            v-model="queryParams.actualReturnAmount"
            placeholder="请输入实退金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="storeSite">
          <el-input
            v-model="queryParams.storeSite"
            placeholder="请输入商店站点"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="storeNo">
          <el-input
            v-model="queryParams.storeNo"
            placeholder="请输入店铺编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item label="" prop="payDateYear">
          <el-input
            v-model="queryParams.payDateYear"
            placeholder="请输入支付日期-年"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="payDateMonth">
          <el-input
            v-model="queryParams.payDateMonth"
            placeholder="请输入支付日期-月"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item label="" prop="payDateDay">
          <el-input
            v-model="queryParams.payDateDay"
            placeholder="请输入支付日期-日"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
        <el-form-item label="" prop="payDateWeek">
          <el-input
            v-model="queryParams.payDateWeek"
            placeholder="请输入业务日期-周"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </div>
      <!-- <el-form-item label="逻辑删除;0=未删除；1=已删除" prop="isDelete">
        <el-input
          v-model="queryParams.isDelete"
          placeholder="请输入逻辑删除;0=未删除；1=已删除"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
    </el-form>
    <el-dialog
      title="选择时间"
      :visible.sync="openInfo"
      width="700px"
      append-to-body
      v-if="openInfo"
    >
      <timeSearch
        @getDateArr="getDateArr"
        @changDay="changDay"
        :timeArr="timeArr"
        :dayActive="this.dayActive"
        :dayLimit="1095"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="handleRefresh">
          同步数据
        </el-button>
      </div>
    </el-dialog>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5" style="display: none">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['product:BiOrderProduct:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5" style="display: none">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['product:BiOrderProduct:edit']"
          >修改</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="handledeleteByPaymentPeriod"
          >删除</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['product:BiOrderProduct:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" plain icon="el-icon-upload" @click="daoru"
          >导入</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshCache"
          >同步数据</el-button
        >
      </el-col> -->

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="openInfo = true"
          >同步</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="orderDataCleansinghandleRefresh"
          >订单清洗</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="orderMarkinghandleRefresh"
          >订单打标</el-button
        >
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <div ref="tableDom">
      <el-table
        :maxHeight="BiOrderProductList.length ? tableHeight : 'auto'"
        v-loading="loading"
        :data="BiOrderProductList"
        @selection-change="handleSelectionChange"
      >
        <!-- <el-table-column width="140" type="selection" width="55" align="center" /> -->
        <el-table-column width="140" label="ID" align="center" prop="id" />
        <el-table-column
          width="140"
          label="内部订单号"
          align="center"
          prop="internalOrderNumber"
        />
        <el-table-column
          width="140"
          label="标记多标签"
          align="center"
          prop="multiLabel"
        />
        <el-table-column
          width="140"
          label="订单属性"
          align="center"
          prop="orderProperties"
        />
        <el-table-column
          width="140"
          label="订单子属性"
          align="center"
          prop="orderSubProperties"
        />
        <el-table-column
          width="140"
          label="订单类型"
          align="center"
          prop="orderType"
        />
        <el-table-column
          width="140"
          label="订单状态"
          align="center"
          prop="orderStatus"
        />
        <el-table-column
          width="160"
          label="店铺"
          align="center"
          prop="shopName"
        />
        <el-table-column
          width="140"
          label="订单小旗"
          align="center"
          prop="orderFlag"
        />
        <el-table-column
          width="140"
          label="买家ID"
          align="center"
          prop="buyerId"
        />
        <el-table-column
          width="140"
          label="卖家备注"
          align="center"
          prop="buyerMark"
        />
        <el-table-column
          width="140"
          label="支付日期"
          align="center"
          prop="payDate"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.payDate, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column
          width="140"
          label="省"
          align="center"
          prop="province"
        />
        <el-table-column width="140" label="市" align="center" prop="city" />
        <el-table-column
          width="140"
          label="售后分类"
          align="center"
          prop="afterSalesClassification"
        />
        <el-table-column
          width="140"
          label="商品编码"
          align="center"
          prop="productCode"
        />
        <el-table-column
          width="140"
          label="款式编码"
          align="center"
          prop="productNo"
        />
        <el-table-column
          width="140"
          label="原始线上订单号"
          align="center"
          prop="origOnlineOrderNumber"
        />

        <el-table-column
          width="140"
          label="线上子订单编号"
          align="center"
          prop="origOnlineSubOrderNumber"
        />
        <el-table-column
          width="140"
          label="线上颜色规格"
          align="center"
          prop="onlineColorSpecification"
        />
        <el-table-column width="140" label="品牌" align="center" prop="brand" />
        <el-table-column
          width="140"
          label="基本售价"
          align="center"
          prop="basicSellingPrice"
        />
        <el-table-column
          width="140"
          label="成本价"
          align="center"
          prop="costPrice"
        />
        <el-table-column
          width="140"
          label="销售数量"
          align="center"
          prop="salesNum"
        />
        <el-table-column
          width="140"
          label="销售金额"
          align="center"
          prop="salesAmount"
        />
        <el-table-column
          width="140"
          label="销售成本"
          align="center"
          prop="salesCost"
        />
        <el-table-column
          width="140"
          label="销售毛利"
          align="center"
          prop="salesGrossProfit"
        />

        <el-table-column
          width="140"
          label="实发数量"
          align="center"
          prop="actualShipmentNum"
        />
        <el-table-column
          width="140"
          label="实发金额"
          align="center"
          prop="actualShipmentAmount"
        />
        <el-table-column
          width="140"
          label="实发成本"
          align="center"
          prop="actualShipmentCost"
        />
        <el-table-column
          width="140"
          label="退货数量"
          align="center"
          prop="returnNum"
        />
        <el-table-column
          width="140"
          label="实退数量"
          align="center"
          prop="actualReturnNum"
        />
        <el-table-column
          width="140"
          label="退货金额"
          align="center"
          prop="returnAmount"
        />
        <el-table-column
          width="140"
          label="实退金额"
          align="center"
          prop="actualReturnAmount"
        />
        <el-table-column
          width="140"
          label="退货成本"
          align="center"
          prop="returnCost"
        />
        <el-table-column
          width="140"
          label="实退成本"
          align="center"
          prop="actualReturnCost"
        />
        <el-table-column
          width="140"
          label="商店站点"
          align="center"
          prop="storeSite"
        />
        <el-table-column
          width="140"
          label="店铺编号"
          align="center"
          prop="storeNo"
        />
        <el-table-column
          width="140"
          label="支付日期-天"
          align="center"
          prop="payDay"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.payDay, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column
          width="140"
          label="支付日期-年"
          align="center"
          prop="payDateYear"
        />
        <el-table-column
          width="140"
          label="支付日期-月"
          align="center"
          prop="payDateMonth"
        />
        <el-table-column
          width="140"
          label="支付日期-日"
          align="center"
          prop="payDateDay"
        />
        <el-table-column
          width="140"
          label="业务日期-周"
          align="center"
          prop="payDateWeek"
        />
        <!-- <el-table-column width="140" label="逻辑删除;0=未删除；1=已删除" align="center" prop="isDelete" /> -->
        <!-- <el-table-column width="140" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['product:BiOrderProduct:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['product:BiOrderProduct:remove']">删除</el-button>
        </template>
      </el-table-column> -->
      </el-table>
    </div>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改t2订单商品明细对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-col :span="10">
          <el-form-item label="内部订单号" prop="internalOrderNumber">
            <el-input
              v-model="form.internalOrderNumber"
              placeholder="请输入内部订单号"
            />
          </el-form-item>
          <el-form-item label="标记多标签" prop="multiLabel">
            <el-input
              v-model="form.multiLabel"
              placeholder="请输入标记多标签"
            />
          </el-form-item>
          <el-form-item label="订单属性" prop="orderProperties">
            <el-input
              v-model="form.orderProperties"
              placeholder="请输入订单属性"
            />
          </el-form-item>
          <el-form-item label="店铺" prop="shopName">
            <el-input v-model="form.shopName" placeholder="请输入店铺" />
          </el-form-item>
          <el-form-item label="" prop="buyerId">
            <el-input v-model="form.buyerId" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="卖家备注" prop="buyerMark">
            <el-input v-model="form.buyerMark" placeholder="请输入卖家备注" />
          </el-form-item>
          <el-form-item label="支付日期" prop="payDate">
            <el-date-picker
              clearable
              v-model="form.payDate"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择支付日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="省" prop="province">
            <el-input v-model="form.province" placeholder="请输入省" />
          </el-form-item>
          <el-form-item label="市" prop="city">
            <el-input v-model="form.city" placeholder="请输入市" />
          </el-form-item>
          <el-form-item label="售后分类" prop="afterSalesClassification">
            <el-input
              v-model="form.afterSalesClassification"
              placeholder="请输入售后分类"
            />
          </el-form-item>
          <el-form-item label="商品编码" prop="productCode">
            <el-input v-model="form.productCode" placeholder="请输入商品编码" />
          </el-form-item>
          <el-form-item label="款式编码" prop="productNo">
            <el-input v-model="form.productNo" placeholder="请输入款式编码" />
          </el-form-item>
          <el-form-item
            label="原始线上订单号"
            prop="onlineOrderNumber"
            label-width="110px"
          >
            <el-input
              v-model="form.onlineOrderNumber"
              placeholder="请输入原始线上订单号"
            />
          </el-form-item>
          <el-form-item label="品牌" prop="brand">
            <el-input v-model="form.brand" placeholder="请输入品牌" />
          </el-form-item>
          <el-form-item label="基本售价" prop="basicSellingPrice">
            <el-input
              v-model="form.basicSellingPrice"
              placeholder="请输入基本售价"
            />
          </el-form-item>
          <el-form-item label="成本价" prop="costPrice">
            <el-input v-model="form.costPrice" placeholder="请输入成本价" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item> </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="销售数量" prop="salesNum">
            <el-input v-model="form.salesNum" placeholder="请输入销售数量" />
          </el-form-item>
          <el-form-item label="销售金额" prop="salesAmount">
            <el-input v-model="form.salesAmount" placeholder="请输入销售金额" />
          </el-form-item>
          <el-form-item label="销售成本" prop="salesCost">
            <el-input v-model="form.salesCost" placeholder="请输入销售成本" />
          </el-form-item>
          <el-form-item label="销售毛利" prop="salesGrossProfit">
            <el-input
              v-model="form.salesGrossProfit"
              placeholder="请输入销售毛利"
            />
          </el-form-item>
          <el-form-item label="退货数量" prop="returnNum">
            <el-input v-model="form.returnNum" placeholder="请输入退货数量" />
          </el-form-item>
          <el-form-item label="实退数量" prop="actualReturnNum">
            <el-input
              v-model="form.actualReturnNum"
              placeholder="请输入实退数量"
            />
          </el-form-item>
          <el-form-item label="退货金额" prop="returnAmount">
            <el-input
              v-model="form.returnAmount"
              placeholder="请输入退货金额"
            />
          </el-form-item>
          <el-form-item label="实退金额" prop="actualReturnAmount">
            <el-input
              v-model="form.actualReturnAmount"
              placeholder="请输入实退金额"
            />
          </el-form-item>
          <el-form-item label="商店站点" prop="storeSite">
            <el-input v-model="form.storeSite" placeholder="请输入商店站点" />
          </el-form-item>
          <el-form-item label="店铺编号" prop="storeNo">
            <el-input v-model="form.storeNo" placeholder="请输入店铺编号" />
          </el-form-item>
          <el-form-item label="支付日期-天" prop="payDay">
            <el-date-picker
              clearable
              v-model="form.payDay"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择支付日期-天"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="支付日期-年" prop="payDateYear">
            <el-input
              v-model="form.payDateYear"
              placeholder="请输入支付日期-年"
            />
          </el-form-item>
          <el-form-item label="支付日期-月" prop="payDateMonth">
            <el-input
              v-model="form.payDateMonth"
              placeholder="请输入支付日期-月"
            />
          </el-form-item>
          <el-form-item label="支付日期-日" prop="payDateDay">
            <el-input
              v-model="form.payDateDay"
              placeholder="请输入支付日期-日"
            />
          </el-form-item>
          <el-form-item label="业务日期-周" prop="payDateWeek">
            <el-input
              v-model="form.payDateWeek"
              placeholder="请输入业务日期-周"
            />
          </el-form-item>
        </el-col>
        <!-- <el-form-item label="逻辑删除;0=未删除；1=已删除" prop="isDelete">
          <el-input v-model="form.isDelete" placeholder="请输入逻辑删除;0=未删除；1=已删除" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改产品二级信息对话框 :on-change="handleChange"-->
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="500px"
      append-to-body
      v-if="dialogVisible"
    >
      <el-upload
        :action="Upload.url"
        :headers="Upload.headers"
        :limit="limit"
        :on-exceed="handleExceed"
        :on-success="handlePictureSuccessPic"
        :before-upload="beforeAvatarUpload"
        :on-preview="handlePictureCardPreview"
        :file-list="fileLi"
        :on-change="changeFile1"
      >
        <el-button size="small" type="primary">导入文件</el-button>
        <!-- <i class="el-icon-plus"></i> -->
      </el-upload>
    </el-dialog>
  </div>
</template>

<script>
import timeSearch from "@/common/day";
//--------导入token
import { getToken } from "@/utils/auth";
import {
  listBiOrderProduct,
  getBiOrderProduct,
  delBiOrderProduct,
  addBiOrderProduct,
  updateBiOrderProduct,
  updateBiOrderProductByDate,
  batchInsertBiOrderProductByDate,
  deleteByPaymentPeriod,
  orderDataCleansing,
  orderMarking,
} from "@/api/chart/BiOrderProduct";
import moment from "moment";
export default {
  name: "BiOrderProduct",
  dicts: ["sys_product_live"],
  components: { timeSearch },
  data() {
    const end = new Date();
    const start = new Date();
    start.setTime(start.getTime() - 30 * 24 * 60 * 60 * 1000); // 30天前
    return {
      openInfo: false,
      dayActive: 2,
      timeArr: [
        { value: "2", label: "昨天" },
        { value: "7", label: "最近7天" },
        { value: "30", label: "最近30天" },
        { value: "365", label: "最近一年" },
        { value: "1", label: "日" },
      ],
      timeGap: { startTime: "", endTime: "" },
      fileLi: [],
      file: "",
      dialogVisible: false,
      // 图片数量限制
      limit: 2,
      Upload: {
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        // 图片上传的方法地址:
        url:
          process.env.VUE_APP_BASE_API +
          "/product/BiOrderProduct/importBiOrderProduct",
      },
      isOpen: false,
      //纵向滚动条
      tableHeight: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // t2订单商品明细表格数据
      BiOrderProductList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        internalOrderNumber: null,
        multiLabel: null,
        orderProperties: null,
        orderType: null,
        orderStatus: null,
        shopName: null,
        buyerId: null,
        buyerMark: null,
        payDate: null,
        province: null,
        city: null,
        afterSalesClassification: null,
        productCode: null,
        productNo: null,
        onlineOrderNumber: null,
        brand: null,
        basicSellingPrice: null,
        costPrice: null,
        salesNum: null,
        salesAmount: null,
        salesCost: null,
        salesGrossProfit: null,
        returnNum: null,
        actualReturnNum: null,
        returnAmount: null,
        actualReturnAmount: null,
        storeSite: null,
        storeNo: null,
        payDay: null,
        payDateYear: null,
        payDateMonth: null,
        payDateDay: null,
        payDateWeek: null,
        isDelete: null,
        onlineColorSpecification: null,
        origOnlineOrderNumber: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        internalOrderNumber: [
          { required: true, message: "内部订单号不能为空", trigger: "blur" },
        ],
      },
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      value1: "",
      value2: [start, end], // 默认选中最近30天
    };
  },
  created() {
    this.changeTime();
  },
  mounted() {
    var _this = this;
    this.resizeTable();
    window.onresize = function () {
      _this.resizeTable();
    };
  },
  //记得清空  如果在keepalive中 则使用activated  deactivated
  destroyed() {
    window.onresize = null;
  },
  methods: {
    changeTime() {
      // console.log(JSON.stringify(this.value2));
      let m1 = moment(this.value2[0]).format("YYYY-MM-DD");
      let m2 = moment(this.value2[1]).format("YYYY-MM-DD");
      // console.log(JSON.stringify(m1));
      // console.log(JSON.stringify(m2));
      this.queryParams.payDayStart = m1;
      this.queryParams.payDayEnd = m2;
      this.getList();
      // this.queryParams.startDate = m1;
      // this.queryParams.endDate = m2;
    },
    //数据清洗
    orderDataCleansinghandleRefresh() {
      // this.$modal.msgWarning("数据正在同步，请稍候")
      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      orderDataCleansing(obj).then((res) => {
        this.$modal.msgWarning(res.msg);
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    //订单打标
    orderMarkinghandleRefresh() {
      // this.$modal.msgWarning("数据正在同步，请稍候")
      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      orderMarking(obj).then((res) => {
        this.$modal.msgWarning(res.msg);
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    handledeleteByPaymentPeriod() {
      // this.$modal.msgWarning("数据正在同步，请稍候")
      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      deleteByPaymentPeriod(obj).then((res) => {
        this.$modal.msgWarning(res.msg);
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在加载数据，请稍候！");
    },
    /** 刷新缓存按钮操作 Warning*/
    handleRefresh() {
      // this.$modal.msgWarning("数据正在同步，请稍候");
      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      this.openLoading();
      batchInsertBiOrderProductByDate(obj).then(() => {
        this.$modal.closeLoading();
        this.$modal.msgSuccess("新增同步数据成功");
        this.openInfo = false;
        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    /** 刷新缓存按钮操作 Warning*/
    handleRefreshCache() {
      this.$modal.msgWarning("数据正在同步，请稍候");
      const obj = {
        startDate: this.timeGap.startTime,
        endDate: this.timeGap.endTime,
      };
      updateBiOrderProductByDate(obj).then(() => {
        this.$modal.msgSuccess("同步数据成功");

        this.getList();
        // this.$store.dispatch('dict/cleanDict');
      });
    },
    //时间控件
    changDay(val) {
      this.dayActive = val;
      this.timeGap.startTime = val[0];
      this.timeGap.endTime = val[1];
    },
    getDateArr(value) {
      this.timeGap.startTime = value[0];
      this.timeGap.endTime = value[1];
      console.log(JSON.stringify(this.timeGap));
      this.dayActive = 1;
    },

    //搜索栏展示与收起
    shouqi() {
      // console.log(1);
      this.isOpen = !this.isOpen;
    },
    /** 查询t2订单商品明细列表 */
    getList() {
      this.loading = true;
      listBiOrderProduct(this.queryParams).then((response) => {
        this.BiOrderProductList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        internalOrderNumber: null,
        multiLabel: null,
        orderProperties: null,
        orderType: null,
        orderStatus: null,
        shopName: null,
        buyerId: null,
        buyerMark: null,
        payDate: null,
        province: null,
        city: null,
        afterSalesClassification: null,
        productCode: null,
        productNo: null,
        onlineOrderNumber: null,
        brand: null,
        basicSellingPrice: null,
        costPrice: null,
        salesNum: null,
        salesAmount: null,
        salesCost: null,
        salesGrossProfit: null,
        returnNum: null,
        actualReturnNum: null,
        returnAmount: null,
        actualReturnAmount: null,
        storeSite: null,
        storeNo: null,
        payDay: null,
        payDateYear: null,
        payDateMonth: null,
        payDateDay: null,
        payDateWeek: null,
        isDelete: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {};
      this.queryParams.pageSize = 10;
      this.value2 = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加t2订单商品明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBiOrderProduct(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改t2订单商品明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBiOrderProduct(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBiOrderProduct(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // table自动高度
    returnTableHeight(ref, bottomOffset) {
      let height = null;
      height =
        window.innerHeight - ref.getBoundingClientRect().top - bottomOffset;
      return height;
    },

    resizeTable() {
      this.$nextTick(() => {
        this.tableHeight = this.returnTableHeight(this.$refs.tableDom, 100);
      }, 0);
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除t2订单商品明细编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBiOrderProduct(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    //部门文件导入修改打开
    daoru() {
      this.dialogVisible = true;
    },
    // 打开加载层
    openUploadLoading() {
      this.$modal.loading("正在导入，请稍候！");
    },
    //文件导入成功回传

    handlePictureSuccessPic(res, file) {
      console.log(JSON.stringify(res));
      //设置图片访问路径 （url 后台传过来的的上传地址）
      // this.picUrl = file.response.url;
      // const url = file.response.fileName;
      this.file = file.response.url;
      console.log(JSON.stringify(this.file));
      if (res.code == 200) {
        this.dialogVisible = false;
        this.$modal.closeLoading();
        this.$modal.msgSuccess(res.msg);
        // if (res.msg == "操作成功") {
        //   this.$modal.msgSuccess("导入成功");
        // } else {
        //   this.$modal.msgError(res.msg);
        // }
        this.getList();
        // return true
      } else {
        this.$modal.msgError(res.msg);
        this.dialogVisible = true;
        // this.$message.msgError('该颜色未在字典定义')
        return;
      }
    },
    //图片预览
    handlePictureCardPreview(file) {
      // this.picUrl = file.url
      // this.imageUrl = file.url;
      // this.dialogVisible = true;
    },
    //图片上传前的相关判断
    beforeAvatarUpload(file) {
      // const isJPG = file.type == 'image/jpeg' || file.type == 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 100;
      // if (!isJPG) {
      //     this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
      // }
      if (!isLt2M) {
        this.$message.error("上传文件大小不能超过 100MB!");
      }
      this.openUploadLoading();
      return isLt2M;
    },

    // 文件个数超出
    handleExceed() {
      this.$modal.msgError(`上传链接文件数量不能超过 ${this.limit} 个!`);
    },
    // 上传文件让第二次覆盖第一的文件
    changeFile1(file, fileList) {
      if (fileList.length > 1) {
        this.fileLi = fileList.slice(-1);

        // this.fileList = [fileList[fileList.length - 1]]//这一步，是 展示最后一次选择文件
      }
      // this.fileSpecial = fileList;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "product/BiOrderProduct/export",
        {
          ...this.queryParams,
        },
        `BiOrderProduct_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
